<?php

require_once "tfsbox_control_panel.class.php";
require_once "tfsbox_login.class.php";

TFsBOX::enableDebugging();

$tfsbox = null;
if (isset($_SERVER['PATH_INFO']))
{
	if (preg_match("#^/tfsbox/cpanel#", TFsBOX::pathInfo()))
	{
		define("TFsBOX_CONTROL_PANEL", 1);
		$tfsbox = new TFsBOXControlPanel;
	}

	else if (preg_match("#^/tfsbox/login#", TFsBOX::pathInfo()))
	{
		define("TFsBOX_USER_LOGIN", 1);
		$tfsbox = new TFsBOXLogin;
	}
}

if (!$tfsbox)
{
	define("TFsBOX_INDEX", 1);
	$tfsbox = new TFsBOX;
}

TFsBOX::$Session->startSession();
$tfsbox->parsePathInfo();

if (!defined("TFsBOX_SHOUTS_ONLY")):
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript" src="<?php echo TFsBOXSession::urlRoot(); ?>/js/jquery-1.4.3.min.js"></script>
<script type="text/javascript" src="<?php echo TFsBOXSession::urlRoot(); ?>/js/jquery-ui-1.8.custom.min.js"></script>
<script type="text/javascript" src="<?php echo TFsBOXSession::urlRoot(); ?>/js/jquery.tools.min.js"></script>
<script type="text/javascript" src="<?php echo TFsBOXSession::urlRoot(); ?>/tfsbox.js"></script>
<script type="text/javascript">
var TFSBOX_SCRIPT_PATH = '<?php echo $_SERVER['SCRIPT_NAME'].'/tfsbox/shouts'; ?>';
var TFSBOX_TIME_OUT = <?php echo TFsBOX::$Config->value('antispam_timeout', 5); ?>000;
<?php if (TFsBOX::$Config->value('auto_refresh', 'yes') == 'yes'): ?>
var TFSBOX_INTERVAL = setInterval(
	function ()
	{
		refresh_shouts(TFSBOX_SCRIPT_PATH);
	},
	TFSBOX_TIME_OUT
);
<?php endif; ?>
<?php if ($tfsbox instanceof TFsBOXLogin): ?>

$(document).ready(
	function ()
	{
		do_focus();
	}
);
<?php endif; ?>
</script>
<title><?php echo TFsBOX::Name ." (v". TFsBOX::Version .")"; ?></title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="robots" content="noindex, nofollow" />
<link rel="stylesheet" media="screen" type="text/css" href="<?php echo TFsBOXSession::urlRoot(); ?>/tfsbox.css" />
<link rel="stylesheet" media="handheld" type="text/css" href="<?php echo TFsBOXSession::urlRoot(); ?>/tfsbox_handheld.css" />
</head>
<body>
<?php

if ($tfsbox instanceof TFsBOXControlPanel)
	$tfsbox->renderControlPanel();
else if ($tfsbox instanceof TFsBOXLogin)
	$tfsbox->renderLogin();
else
	$tfsbox->renderShoutBox();

TFsBOXAbstractView::renderInputDialog();
TFsBOXAbstractView::renderMessageDialog();
TFsBOXAbstractView::renderTooltip();

?>
<div id="screen"></div>
</body>
</html>
<?php

else:
	TFsBOX::$View->renderShouts();
endif;

?>
